package leetcode.tree;

import java.util.ArrayList;
import java.util.List;

/**
 * 145. 二叉树的后序遍历
 */
public class _145 {


    public List<Integer> postorderTraversal(TreeNode root) {
        List<Integer> result = new ArrayList<>();

        getChild(result, root);

        return result;
    }

    public static void getChild(List<Integer> result, TreeNode cur) {
        if (cur == null) {
            return;
        }

        getChild(result, cur.left);
        getChild(result, cur.right);
        result.add(cur.val);

    }


    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

}
